package cn.assumejson.springframework.context.context.annotation;

import cn.assumejson.springframework.beans.factory.FactoryBean;
import cn.assumejson.springframework.context.stereotype.Component;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author gang.Li
 * @version 1.0
 * @since 1.0 2021/12/11 0:05
 */
//@Component
public class UserFactoryBean implements FactoryBean {
    @Override
    public Object getObject() throws Exception {
        UserService o = (UserService) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]{IUserService.class}, new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println(method.getName());
                return null;
            }
        });
        return o;
    }

    @Override
    public Class<?> getObjectType() {
        return IUserService.class;
    }
}
